﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Model;
using Public.Tools;
using Newtonsoft.Json;
using System.Net.Http;
using System.Text;
using Public;

namespace wochu.DPS.API.Infrastructure
{
    public class ResultsExtensions
    {
        #region GetSuccessJson
        /// <summary>
        /// 自定义返回ResultModel，作用于APP
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static HttpResponseMessage GetSuccessJson(object obj)
        {
            var resultModel = new ResultModel
            {
                DATA = obj,
                MESSAGE = "请求成功",
                RESULT = Consts.strSucess

            };
            return new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(resultModel)
                , Encoding.GetEncoding("UTF-8"), "application/json") };
        }
        /// <summary>
        /// 返回传入对象数据，作用于PDA
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        //public static HttpResponseMessage GetSuccessJson<T>(T t)
        //{
           
        //    return new HttpResponseMessage
        //    {
        //        Content = new StringContent(JsonConvert.SerializeObject(t)
        //            , Encoding.GetEncoding("UTF-8"), "application/json")
        //    };
        //}
        #endregion

        #region GetFailJson
        /// <summary>
        /// 自定义返回ResultModel，作用于APP
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static HttpResponseMessage GetFailJson(SysSetting obj)
        {
            var resultModel = new ResultModel
            {
                //DATA = obj,
                MESSAGE = obj.Value,
                //RESULT = obj.Key
                RESULT = "0"

            };
            return new HttpResponseMessage
            {
                Content = new StringContent(JsonConvert.SerializeObject(resultModel)
                    , Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }
        /// <summary>
        /// 自定义返回ResultModel，作用于APP
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static HttpResponseMessage GetFailJson(SysSetting sys,object obj)
        {
            var resultModel = new ResultModel
            {
                DATA = obj,
                MESSAGE = sys.Value,
                RESULT = sys.Key

            };
            return new HttpResponseMessage
            {
                Content = new StringContent(JsonConvert.SerializeObject(resultModel)
                    , Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }
        /// <summary>
        /// 返回传入对象数据，作用于PDA
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static HttpResponseMessage GetFailJson<T>(T t)
        {
            return new HttpResponseMessage
            {
                Content = new StringContent(JsonConvert.SerializeObject(t)
                    , Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }

        /// <summary>
        /// 返回空值，作用于PDA
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static HttpResponseMessage GetFailJsonRuturnNull()
        {
            return new HttpResponseMessage
            {
                Content = new StringContent(""
                    , Encoding.GetEncoding("UTF-8"), "application/json")
            };
        }
        #endregion
 
    }
}